package com.example.controller;

import com.example.domain.Result;
import com.example.domain.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author 59400
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    //有look权现才能访问
    @GetMapping("/look")
    @PreAuthorize("hasAuthority('sys:user:look')")
    public String look(){
        return "look";
    }

    @GetMapping("/look2")
    @PreAuthorize("hasAuthority('look2')")
    public String look2(){
        return "look2";
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        return userService.login(user);
    }

    @PostMapping("/logout")
    public Result logout(){
        return userService.logout();
    }



}
